<template>
  <div class="box">
    <div class="top">
      <div class="title-box">
        <span class="title">年龄比例</span>
        <img src="../../images/dataScreen-title.png" />
      </div>
    </div>
    <div class="ageChart" ref="ageChartRef"></div>
  </div>
</template>

<script setup lang="ts" name="age">
import * as echarts from 'echarts'
import { onMounted, ref } from 'vue'

let ageChartRef = ref()
onMounted(() => {
  initChart()
})
//饼图
function initChart() {
  let ageChart = echarts.init(ageChartRef.value)
  let option = {
    tooltip: {
      trigger: 'item',
    },
    legend: {
      orient: 'vertical',
      top: '5%',
      right: 10,
      show: true,
      textStyle: {
        color: 'white',
      },
    },
    series: [
      {
        type: 'pie',
        radius: ['40%', '70%'],
        label: {
          show: false,
        },
        data: [
          { value: 100, name: '18岁以下' },
          { value: 200, name: '18岁以上' },
          { value: 300, name: '25岁以上' },
          { value: 400, name: '30岁以上' },
          { value: 500, name: '35岁以上' },
          { value: 600, name: '40岁以上' },
        ],
        emphasis: {
          itemStyle: {
            shadowBlur: 10,
            shadowOffsetX: 0,
            shadowColor: 'rgba(0, 0, 0, 0.5)',
          },
        },
      },
    ],
  }
  ageChart.setOption(option)
}
</script>

<style scoped lang="scss">
.box {
  width: 100%;
  height: 100%;
  background: url('../../images/dataScreen-main-lb.png') no-repeat;
  background-size: 100% 100%;
  margin-top: 20px;
  .title-box {
    margin-left: 20px;
    display: flex;
    flex-direction: column;

    .title {
      font-size: 20px;
      color: #fff;
    }
    img {
      margin-top: 7px;
      width: 68px;
      height: 7px;
    }
  }
  .ageChart {
    width: 100%;
    height: 100%;
  }
}
</style>
